<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>
	<meta http-equiv="content-type" content="text/xml; charset=utf-8" /> 
    <?php 
		if ($selection == "general") {
			echo '<title>Tour Information</title>';
		} else if ($selection == "detail") {
			echo '<title>'.$record['t_name'].'</title>';
		} else if ($selection == "short") {
			$result_region = mysql_query("Select * From region Where regionID='$regionID'");
			$record_region = mysql_fetch_array($result_region);
			echo '<title>'.$record_region['r_name'].'</title>';
		}
	?>
    <meta name="description" content="Green Travel Tour Information"  /> 
	<meta name="keywords" content="tour, green travel, rmit, project, e-business, semester 2012A, tour information, vietnam, vietnam travel"  /> 
	<link rel="stylesheet" type="text/css" href="formatstyles.css"/> 
	<link rel="stylesheet" type="text/css" href="divstyles.css"/> 
    <link rel="stylesheet" type="text/css" href="style/css/jquery-ui-1.8.18.custom.css" />
	
	<!-- include CSS always before including js -->

	<!-- include jQuery library -->
	<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
	<script type="text/javascript" src="js/jquery-1.7.2.js"></script>
	<script type="text/javascript" src="js/jquery.cycle.all.js"></script>
	<script type="text/javascript" src="js/scripts.js"></script>
	<script type="text/javascript" src="js/tablecloth.js"></script>
	<script type="text/javascript" src="js/jquery-ui-1.8.18.custom.min.js"></script>
	<script type="text/javascript" src="js/login.js"></script>
	<script type="text/javascript" src="js/comment.js"></script>
	<link rel="stylesheet" type="text/css" media="screen" href="style/css/demos.css"/>
	<style type="text/css" media="screen"> 
		@import "style/css/uni-form.css"; 
	</style>
	
	<!-- Demo page js -->
	<script type="text/javascript" src="js/jquery.uni-form.js"></script>
	
	<!-- Star Rating widget stuff here... -->
	<script type="text/javascript" src="js/jquery.ui.stars.js"></script>
	<link rel="stylesheet" type="text/css" href="style/css/crystal-stars.css"/>
	<link rel="stylesheet" type="text/css" href="style/css/jquery.ui.stars.css"/>
	<script type="text/javascript" src ="js/language-en.js"></script> 
	<script type="text/javascript" src ="js/nopcart.js" language="javascript"> 
	
      //============================================================== 
      //               NOP Design JavaScript Shopping Cart               
      //-------------------------------------------------------------- 
	  //       Visit NOP Design at http://www.nopdesign.com/freecart     
	  //============================================================== 
	</script> 
<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
</head>

<body>
<div id="fade" style="display:none;"></div>
	<!-- This is the page section -->
	<div id="page_section">

		<!-- This is the banner --> 
		<div> 
 			<?php include("banner.php"); ?>
		</div> 
		<!-- This is end of the banner --> 
    
    	<div id="user-cpanel">
			<?php include("user_cpanel.php"); ?>
        </div>
        
        <div class="wan-clear"></div>
        
        <div id="user-form">
       		<?php include("user-form.php"); ?>
		</div>
        
		<div id="topnav">
           <?php include("top-nav.php"); ?>
        </div>
			
		<div id="left-top">
            <div class="title-text">Search Tour</div>
            <?php include("search-form.php"); ?>	    
		</div>
		
		<div id="right-top">
            <?php
            	if ($selection == "general") {
                	echo '
                    <div class="dynamic_drive">
						<a href="tour.php?reg=0">Tour</a>
    				</div>
                                        
                    <div id="display_general">
                    	<p>Please select the region you are looking for</p>
                        <table>
                            <tr>';
                                $i = 1;
                                while ($record = mysql_fetch_array($result)) {
                                    echo '<td><a href="tour.php?reg='.$i.'">'.$record['r_name'].'</a></td>';
                                    $i = $i + 1;
                                } echo '
                            </tr>
                        </table>
                    </div>';
                }
                
                if ($selection == "short") {
                	$first = true;
					
                    while($record = mysql_fetch_array($result)){
                    	if ($first == true) {
                            echo '<div class="dynamic_drive">
                                      <a href="tour.php?reg=0">Tour</a> >>                  
                                      <a href="tour.php?reg='.$regionID.'">'.$record['r_name'].'</a>
								  </div>';
                            $first = false;
                        }
                        echo'
                    	<div class="tour">';
                            $id = $record['tourID'];
                            $shortDescription = substr($record['description'], 0, 200);
                            echo '
                            <img width ="300" height="200" src="'.$record['image'].'" alt="Image cannot be loaded" align="left" />
                            <a class="tour_name" href="tour.php?tourID='.$id.'">'.$record['t_name'].'</a><br /><br />';
                            
                            echo $shortDescription.'...<br /><a href="tour.php?tourID='.$id.'"><input type="button" value="More Details" /></a><br /><br />';
						echo '</div>';
                    }
                }
                
                if ($selection == "detail") {
                    echo '<div class="dynamic_drive">
                              <a href="tour.php?reg=0">Tour</a> >> 
                              <a href="tour.php?reg='.$record['regionID'].'">'.$record['r_name'].'</a>
        				  </div>
                    <div id="tour_content">
                        <div class="tour_name"><center>'.$record['t_name'].'</center></div>
                        
                        <div id="top_details">
                            <img width ="300" height="200" src="'.$record['image'].'" alt="Image cannot be loaded" align="left" />
                            <b>Duration: </b>'.$record['duration'].'<br />
                            
                            <b>Price: </b>'.number_format($record['price']).' VND<br />
                            <b>Occurance Day: </b>';
                            $stringOccurance ="";
                            while ($occurance = mysql_fetch_array($occurance_result)) {
                                $stringOccurance .= $occurance['dayName'].', ';
                            }
                            echo substr($stringOccurance,0,strlen($stringOccurance)-2);

                            echo '<br />';
                            
                            if(mysql_num_rows($result_rate) > 0) {
                                $record_rate =  mysql_fetch_array($result_rate);
                                $avg = round($record_rate['sum']/$record_rate['count'],1);
                                        
                            	echo '<b>Rate:</b><div id="avg">'.$avg.'/5</div> from '.$record_rate['count'].' review(s)<br />'; 
                            } else {
                            	echo '<b>Rate:</b><div id="avg">0</div>review<br />';
                            }

                            if (isset($_SESSION['login'])==true &&( $_SESSION['login'])==true) {
                                echo '<a href="booking.php?tourID='.$tourID.'"><input type="button" value="Book Now" /></a>';
                                if ($_SESSION['username']=="inte") {
                                    echo '<a href="history.php?tourID='.$tourID.'"><input type="button" value="Retrieve History" /></a>';
                                }
                            } else {
                                echo '<i>You need to <a href="javascript:toggleLogin();">login</a> before booking tour. Do not have an account? Click <a href="registration.html">here</a></i>';
                            }
                         
						echo '</div>';
                        $currentURL = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
						echo '<div class="fb-like" data-href="'.$currentURL.'" data-send="true" data-width="450" data-show-faces="false"></div><br/>
                        <g:plusone></g:plusone>';
						echo '<div id="description"><b>Description: </b><br /><br />'.$record['description'].'</div></div>';

                    if(mysql_num_rows($result_review) > 0) {
                        echo '<div class="title-text" style="margin-top:20px">Customer Review</div>';
                            $id =1;
                            echo '<div id="review">';
                            while ($record_review =  mysql_fetch_array($result_review)) {
                                $title = $record_review['title'];
                                $comment = $record_review['comment'];
                                $rate = $record_review['rate'];
								$temp = date_create($record_review['r_date']);
								$date= date_format($temp,"F j, Y");
                                $username = $record_review['username'];
                                
                                echo '
                                <table><tr><th><b>Subject: '.$title.'</b></th></tr>
                                <tr><td>';

								if ($rate ==1) {
									echo '<div id="'.$id.'">
                                	<input type="radio" id="rate1"  value ="1"  checked="checked" />
                                	<input type="radio" id="rate2"  value ="2" />
                                	<input type="radio" id="rate3"  value ="3" />
                                	<input type="radio" id="rate4"  value ="4" />
                                	<input type="radio" id="rate5"  value ="5" /></div>';
								} else if ($rate ==2) {
									echo '<div id="'.$id.'">
                                	<input type="radio" id="rate1"  value ="1" />
                                	<input type="radio" id="rate2"  value ="2" checked="checked" />
                                	<input type="radio" id="rate3"  value ="3" />
                                	<input type="radio" id="rate4"  value ="4" />
                                	<input type="radio" id="rate5"  value ="5" /></div>';
								} else if ($rate ==3) {
									echo '<div id="'.$id.'">
                                	<input type="radio" id="rate1"  value ="1" />
                           	    	<input type="radio" id="rate2"  value ="2" />
                                	<input type="radio" id="rate3"  value ="3" checked="checked" />
                           	     	<input type="radio" id="rate4"  value ="4" />
                        	        <input type="radio" id="rate5"  value ="5" /></div>';
								} else if ($rate ==4) {
									echo '<div id="'.$id.'">
                                	<input type="radio" id="rate1"  value ="1" />
                               	 	<input type="radio" id="rate2"  value ="2" />
                                	<input type="radio" id="rate3"  value ="3" />
                                	<input type="radio" id="rate4"  value ="4" checked="checked" />
                                	<input type="radio" id="rate5"  value ="5" /></div>';
								} else if ($rate ==5) {
									echo '<div id="'.$id.'">
                                	<input type="radio" id="rate1"  value ="1" />
                                	<input type="radio" id="rate2"  value ="2"/>
                                	<input type="radio" id="rate3"  value ="3" />
                                	<input type="radio" id="rate4"  value ="4" />
                                	<input type="radio" id="rate5"  value ="5" checked="checked" /></div>';
								}
						
								echo '<div class="light"> by <i>'.$username.'</i> on '.$date.'</div></td></tr>
                                <tr><td>'.$comment.'</td></tr></table><br />';
                                
                                echo'<script>
                                $(function(){
                                    $("#'.$id.'").children().not(":radio").hide();
                                    $("#'.$id.'").stars({
                                    cancelShow: false,
                                    disabled: true,
                                    });
                                });							
                                </script>';
                                $id +=1;
                                }
                            echo '</div>';
                    	}	

                    if (isset($_SESSION['login'])==true &&( $_SESSION['login'])==true) {
                        $username = $_SESSION['username'];
                        $result = mysql_query("SELECT * FROM tour_booking where username='$username' and tourID = '$tourID'");
                        
   						$record = mysql_fetch_array($result);
                        
                        if(mysql_num_rows($result) > 0) {
                            echo '
                            	  <form action="add_review.php" method="post" id="make_review">	
        
                            <fieldset><legend>Comment</legend>
        						<input type="hidden" id="tourID" value="'.$tourID.'" />
                                <input type="hidden" id="tour_booking_id" value="'.$record['tour_booking_id'].'" />
                                <table>
                                	<tr>
                                    	<div class="ctrlHolder">
                                    	<td><label for="name">Title *</label></td>
                                        <td><input name="title" id="title" type="text" onchange="isEmpty(\'title\');"/>
                                			<span id="title" style="display:none; color: #FF4040;"></span></div>
                                        </td>
                                    </tr>
                                    
                                    <tr>
                                    	<div class="ctrlHolder">
                                    	<td valign="top"><label for="message">Comment *</label></td>
                                        <td><textarea name="comment" id="comment" onchange="isEmpty(\'comment\');" ></textarea>
	                                        <span id="comment" style="display:none;color: #FF4040;margin-left:85px;"></span></div>
                                        </td>
                                    </tr>
                                    
                                    <tr>
                                    	<div class="ctrlHolder">
                                    	<td>Rate *</td>
                                        <td><div class="multiField" id="starify">
                                            <label for="vote1" class="blockLabel"><input type="radio" name="vote" id="vote1" value="1" /> Poor</label>
                                            <label for="vote2" class="blockLabel"><input type="radio" name="vote" id="vote2" value="2" /> Fair</label>
                                            <label for="vote3" class="blockLabel"><input type="radio" name="vote" id="vote3" value="3" /> Average</label>
                                            <label for="vote4" class="blockLabel"><input type="radio" name="vote" id="vote4" value="4" /> Good</label>
                                            <label for="vote5" class="blockLabel"><input type="radio" name="vote" id="vote5" value="5" /> Excellent</label>
                                			</div>
                                            <span id="vote" style="display:none;color: #FF4040;margin-left:15px;"></span></div>
                                        </td>
                                        
                                    </tr>
                                </table>
                                
                                <div id="summary_error" style="color:red"></div>
                                <div class="buttonHolder" style="margin-top:10px">
                                
                                <center><button type="button" onclick="submitCommentForm();" class="primaryAction">Submit</button>
                                <button type="reset" class="primaryAction">Reset</button></center></div>
                            </fieldset></form>';
                        }
                    }	
				} 
            ?>
		</div>

		<div class="wan-clear"></div>
		
<!-- This is end of the content -->
	</div> 
<!-- This is end of the page section -->
<br />
<!-- This is the footer -->
		<div id="footer"> 
			<p class="footer">This website is a student project that is intended to be used only for academic purposes. This page was created by Dat, Duong Xuong</p>
		</div> 
<!-- This is end of the footer -->
</body>

</html>